# -*- coding: utf-8 -*-
# @Time : 2025/1/25 14:43
# @Author : debbyszhang
# @File : settings.py
# @desc :
import os
import sys
from distutils.util import strtobool

from libs.tools.configParse import ConfigParse


def get_env_config(env):
    env_config = {}
    config_file = ConfigParse(os.path.join(PROJECT_ROOT, 'config', f'config-{env}.ini'))
    print("config_file=====", config_file.file_path)
    env_config.update(dict({'base_url': config_file.get_value('HOST', 'base_url'),
                            'user_root': config_file.get_value('ACCOUNT', 'user_root'),
                            'user_root_password': config_file.get_value('ACCOUNT', 'user_root_password'),
                            'user_cross': config_file.get_value('ACCOUNT', 'user_cross'),
                            'user_cross_password': config_file.get_value('ACCOUNT', 'user_cross_password'),
                            'user_relay': config_file.get_value('ACCOUNT', 'user_relay'),
                            'user_relay_password': config_file.get_value('ACCOUNT', 'user_relay_password'),
                            'head_less': config_file.get_value('HOST', 'head_less'),

                            }))
    print('env_config:===', env_config)
    return env_config


PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(PROJECT_ROOT)

print("PROJECT_ROOT=" + PROJECT_ROOT)

# 设置运行环境
ENV = 'jenkins'  # choices=['jenkins', 'test', 'pre']
# ENV = 'jenkins'  # choices=['jenkins', 'test', 'pre']

env_config = get_env_config(ENV)

BASE_URL = env_config['base_url']
USER_ROOT = env_config['user_root']
USER_ROOT_PASSWORD = env_config['user_root_password']
USER_CROSS = env_config['user_cross']
USER_CROSS_PASSWORD = env_config['user_cross_password']
USER_RELAY = env_config['user_relay']
USER_RELAY_PASSWORD = env_config['user_relay_password']
HEAD_LESS = bool(strtobool(env_config['head_less']))

# 可定义多个文件路径
FILE_PATH = {
    'log': os.path.join(PROJECT_ROOT, 'logs'),
    'report': os.path.join(PROJECT_ROOT, 'report'),
}

# print(FILE_PATH['log'])
if not os.path.exists(FILE_PATH['log']):
    os.makedirs(FILE_PATH['log'])
if not os.path.exists(FILE_PATH['report']):
    os.makedirs(FILE_PATH['report'])
